package com.shkco.system.controller;

import com.shkco.basic.util.PageList;
import com.shkco.basic.util.AjaxResult;
import com.shkco.system.domain.Systemdictionarytype;
import com.shkco.system.query.SystemdictionarytypeQuery;
import com.shkco.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;


    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id")Long id){
        return systemdictionarytypeService.findById(id);
    }

    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            systemdictionarytypeService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Systemdictionarytype type){
        try {
            if (type.getId() == null){
                systemdictionarytypeService.add(type);
            } else {
                systemdictionarytypeService.update(type);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PostMapping
    public PageList<Systemdictionarytype> pageQuery(@RequestBody SystemdictionarytypeQuery typeQuery){
        return systemdictionarytypeService.queryPage(typeQuery);
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.patchDel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

}
